package com.kuang.pet.service;

import com.kuang.bascic.service.BaseServiceImpl;
import com.kuang.bascic.utils.DistanceUtil;
import com.kuang.bascic.utils.LoginContext;
import com.kuang.bascic.utils.Point;
import com.kuang.org.domain.Shop;
import com.kuang.org.mapper.ShopMapper;
import com.kuang.pet.domain.SearchMasterMsg;
import com.kuang.pet.mapper.SearchMasterMsgMapper;
import com.kuang.user.domian.LoginInfo;
import com.kuang.user.domian.User;
import com.kuang.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Service
public class SearchMasterMsgServiceImpl extends BaseServiceImpl<SearchMasterMsg> implements SearchMasterMsgService {
    @Autowired
    private SearchMasterMsgMapper searchMasterMsgMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public void publish(SearchMasterMsg msg, HttpServletRequest req) {
        // 添加宠物信息的逻辑
        // 1.完善发布信息（获取到当前的用户） 从U-TOKEN里面获取的是 当前的登陆信息logininfo
        // U-TOKEN是用户的登录信息 拦截器拦截的token把他设置到了请求头里
        User currenUser = (User) LoginContext.getCurrenUser(req);
        msg.setUser_id(currenUser.getId());
        // 完善最近店铺信息
        // 首先获取用户的经纬度 在和店铺地址做比较得到最近店铺
        Point point = DistanceUtil.getPoint(msg.getAddress());
        // 比较得到最近的店铺地址 查询全部店铺
        List<Shop> shops = shopMapper.selectAllDepartment();
        // 调用方法比较的到最近的店铺
        Shop shop = DistanceUtil.getNearestShop(point, shops);
        msg.setShop_id(shop.getId());
        // 修改状态为待审核
        msg.setState(1);
        searchMasterMsgMapper.addDepartment(msg);


        //作业  将数据库地址字段分离一个省份
    }

















}
